<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript" src=".././static/js/public-head.js"></script>
</head>
<body >

<div class="layui-form-item">
    <div class="layui-inline">
        <div class="layui-input-inline">
            <input  type="text"   name="searchStr" id="searchStr" placeholder="输入关键字" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">选中绑定参数</div>
    </div>
    <table id="viewParam-tb" lay-filter="viewParam-tb"></table>
</div>


</body>

<script type="text/javascript">
    layui.use([  'form','table' ], function() {
        var $ = layui.$;
        table = layui.table;
        layer = layui.layer
        var tableOption = {
            elem: '#viewParam-tb'
            ,url: basePath +  '/xdWidget/listXdWidget'+urlParam
            ,where:{searchStr:function(){return $("input[name='searchStr']").val()}}
            ,method:"post"
            ,toolbar:false
            ,title:"系统参数配置"
            ,defaultToolbar:false//['filter', 'print']
            ,cols: [[
                { width:60, title: '选择',type:'normal',templet:function(d){
                     var checked = ""
                    if(d.PANEL_ID !=null && d.PANEL_ID != ""){
                        checked = "checked"
                    }
                     return '<input name="layTableCheckbox" panel-id="'+d.PANEL_ID+'"' +
                             ' lay-skin="primary" lay-filter="bind-param" value='+d.ID+'  type="checkbox"  '+checked+'  >'
                } },
                {field:'NAME', title: '名称' ,sort:true,templet:function(d){
                    var str = d.NAME
                    if( d.LABEL){
                        str = d.NAME +"("+ d.LABEL+")"
                    }
                    return  str
                }}

                ,{field:'XD_WIDGET', width:100, title: '标签',sort:true }

                ,{title: "操作", width:60,fixed:'right',
                    templet:function(d){
                        return '<a class="layui-btn layui-btn-danger layui-btn-xs copyName" lay-event="copyName">复制</a>'
                    }}
            ]]
            ,page: {groups:3,layout:['prev', 'page', 'next','refresh']}
            ,height: 'full-70'
        }


        var tableDom = table.render(tableOption)

        table.on("tool(viewParam-tb)",function(obj){
            var event = obj.event;
            if(event == "copyName"){
                var copyContent = obj.data.NAME;
                commonUtil.copyToClipBoard('.copyName',copyContent);
                layer.msg("已复制参数："+copyContent+" 到剪切板")
            }
        })

        //选中事件
        table.on("checkbox(viewParam-tb)",function(obj){
            var checked = obj.checked
            var paramId = obj.data.ID
            var classFlag = obj.data.CLASS_FLAG
            var flag = "add"
            if(checked != true){//选中则增加配置
                flag = "del"
            }
            $.getJSON( basePath +"/xdWidgetPanel/cfgPanelParam"+urlParam,{paramId:paramId,classFlag:classFlag,flag:flag},function(rst){
                if(rst.code !=0){
                    layer.msg(rst.msg)
                }
            })

        })


        $("#searchStr").bind('input propertychange', function() {
            table.reload("viewParam-tb")
        });


    });

</script>
